﻿using System.IO;
using System.Runtime.Serialization;

namespace Sunyi.Project.WebPoint.Common
{
    public static class SerializationHelper
    {
        public static string Serialize<T>(T obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(T));

                serializer.WriteObject(ms, obj);

                ms.Position = 0;
                StreamReader sr = new StreamReader(ms);
                return sr.ReadToEnd();
            }
        }
    }
}
